#include "outThread.h"

OutThread::OutThread()
{
    pTimer = NULL ;
}

OutThread & OutThread::getInstance ()
{
    static OutThread OutThread ;
    return OutThread ;
}

void OutThread::operator()(boost::asio::io_service& io) 
{
    initPolling(io) ;
}

void OutThread::initPolling (boost::asio::io_service& io)
{
    pTimer = new boost::asio::deadline_timer(io, boost::posix_time::milliseconds(20)) ;
    pTimer->async_wait(boost::bind(&OutThread::rxMsg, this)) ;
}
    
void OutThread::rxMsg () 
{
    std::cout<< "OutThread: Receive a msg" << std::endl ;
    
    pTimer->expires_at(pTimer->expires_at() + boost::posix_time::milliseconds(20));
    pTimer->async_wait(boost::bind(&OutThread::rxMsg, this));
}
